package com.hb.trans.mvp.ui.fragment


import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.launcher.ARouter
import com.basiclib.base.BaseFragment
import com.basiclib.view.SnackbarUtil
import com.hb.trans.R
import com.hb.trans.bean.Coach
import com.hb.trans.bean.EnrollCount
import com.hb.trans.bean.SchoolDetail
import com.hb.trans.global.ACTIVITY_SCHOOL_INFO_COACH_INFO
import com.hb.trans.mvp.contract.SchoolInfoContract
import com.hb.trans.mvp.presenter.SchoolInfoPresenter
import com.hb.trans.mvp.ui.adapter.CoachAdapter
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_school_info_item.*
import javax.inject.Inject


class SchoolInfoItemFragment : BaseFragment<SchoolInfoPresenter>(), SchoolInfoContract.View {

    override fun setViewId(): Int {
        return R.layout.fragment_school_info_item
    }

    @Inject
    lateinit var mAdapter: CoachAdapter
    @Inject
    lateinit var mPresenter: SchoolInfoPresenter

    var schoolDetail: SchoolDetail? = null

    override fun setupSchoolDetail(schoolDetail: SchoolDetail?) {
        this.schoolDetail = schoolDetail
        schoolDetail?.let {
            var coach = Coach("智能教练", "测试", "", "", "", "", null)
            it.coas.add(0, coach)
            if (it.coas.size > 0) {
                showDataView()
                mAdapter.setNewData(it.coas)
            } else {
                showNoDataView()
            }
        }



    }


    override fun setupEnrollCount(enrollCount: EnrollCount?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun doOnInvisible() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun doOnVisible() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }





    override fun onFragmentInject() {
        AndroidSupportInjection.inject(this)
    }

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun initView() {
        rvSchoolCoach3.apply {
            adapter = mAdapter
        }
    }

    override fun initData() {
        var bundle: Bundle? = arguments ?: return
        var inscode = bundle?.getString("inscode")
        mPresenter.getSchoolCoach(inscode)
    }

    override fun setListener() {
        mAdapter.setOnItemClickListener { adapter, _, position ->
            if (position != 0) {
                ARouter.getInstance().build(ACTIVITY_SCHOOL_INFO_COACH_INFO)
                    .withObject("coachInfo", adapter.getItem(position))
//                    .withOptionsCompat(compat)
                    .navigation(mContext)
            } else {
//                ARouter.getInstance().build(ACTIVITY_NO_DETAIL).navigation()
                showShortToast("暂未开通", SnackbarUtil.INFO)
            }
//            var name:TextView =  adapter.getViewByPosition(rvSchoolCoach3,position,R.id.teacher_name) as TextView
//            var s = name.text.toString()
//            showShortToast(name.text.toString())
            }

    }


    private fun showNoDataView() {
        rlNoData.visibility = View.VISIBLE
        rvSchoolCoach3.visibility = View.GONE
    }

    private fun showDataView() {
        rlNoData.visibility = View.GONE
        rvSchoolCoach3.visibility = View.VISIBLE
    }
}
